package com.zj.ssm.service.impl;

import com.zj.ssm.mapper.NewsStatusMapper;
import com.zj.ssm.pojo.domain.News;
import com.zj.ssm.pojo.domain.query.NewsOpinionsQuery;
import com.zj.ssm.pojo.domain.query.NewsStatusQuery;
import com.zj.ssm.pojo.domain.vo.NewsVO;
import com.zj.ssm.result.AjaxResult;
import com.zj.ssm.service.NewsStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

/**
 * @author wxr
 * @version 1.0
 * @date 2022/1/14 10:33
 */
@Service
public class NewsStatusServiceImpl implements NewsStatusService {


    @Autowired
    private NewsStatusMapper newsStatusMapper;
    @Override
    public AjaxResult queryAll(NewsStatusQuery newsStatusQuery) {

        List<News> news = newsStatusMapper.queryNews(newsStatusQuery);
        Long aLong = newsStatusMapper.queryNewsTotal(newsStatusQuery);
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("currentData",news);
        objectObjectHashMap.put("totalCount",aLong);
        return AjaxResult.success(objectObjectHashMap);
    }

    @Override
    public AjaxResult queryNews(NewsOpinionsQuery newsOpinionsQuery) {
        List<News> news = newsStatusMapper.queryShowNews(newsOpinionsQuery);
        Long aLong = newsStatusMapper.queryShowNewsTotal(newsOpinionsQuery);
        HashMap<Object, Object> data = new HashMap<>();
        data.put("currentDataShow",news);
        data.put("totalCountShow",aLong);
        return AjaxResult.success(data);
    }

    @Override
    public AjaxResult getNews(Integer id) {
        News n = newsStatusMapper.get(id);
        return AjaxResult.success(n);
    }

    @Override
    public AjaxResult update(NewsVO newsVO) {
        String[] str1 = {"草","操","滚"};
        String[] str2 = {"SB","Sb","sB","sb","傻瓜",};
        String[] str3 = {"大法好","大傻瓜","真可爱","TMD"};
        for (String m : str1){
            String result = newsVO.getTotal().replace(m,"*");
            String result1 = newsVO.getContent().replace(m,"*");
            newsVO.setTotal(result);
            newsVO.setContent(result1);
        }
        for (String m : str2){
            String result = newsVO.getTotal().replace(m,"**");
            String result1 = newsVO.getContent().replace(m,"**");
            newsVO.setTotal(result);
            newsVO.setContent(result1);
        }
        for (String m : str3) {
            String result = newsVO.getTotal().replace(m, "***");
            String result1 = newsVO.getContent().replace(m, "***");
            newsVO.setTotal(result);
            newsVO.setContent(result1);
        }
//        if(newsVO.getTotal().contains("*")== true || newsVO.getContent().contains("*") == true){
//            newsVO.setSid(1);
//        }else{
//            newsVO.setSid(0);
//        }
        int i = newsStatusMapper.update(newsVO);
        if(i > 0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }
    }



